//
//  THCpcMyJoinTaskDetailVC.m
//  YJB
//
//  Created by YJB on 2016/11/29.
//  Copyright © 2016年 YJB. All rights reserved.
//

#import "THCpcMyJoinTaskDetailVC.h"
#import "YJUserDefaultTool.h"
#import "YJNetworkTool.h"

@interface THCpcMyJoinTaskDetailVC ()
@property (weak, nonatomic) IBOutlet UILabel *adsTitle;
@property (weak, nonatomic) IBOutlet UILabel *stopTime;
@property (weak, nonatomic) IBOutlet UILabel *award;
@property (weak, nonatomic) IBOutlet UILabel *adsUrl;
@property (weak, nonatomic) IBOutlet UILabel *date;

@end

@implementation THCpcMyJoinTaskDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"参与CPC详情";
    [self loadData];
}

- (void)loadData
{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    NSString *userName = [YJUserDefaultTool readUserName];
    NSString *md5Key = [YJUserDefaultTool readKeyID];
    params[@"action"] = @"get_involve_one";
    params[@"makegold"] = @{@"task_id":_taskId,
                            @"user_info":userName,
                            @"phone_info":@"iOS",
                            @"md5_key":md5Key};
    [MBProgressHUD showMessage:@"加载中.." toView:self.view];
    [YJNetworkTool postWithUrl:THURL(@"clickcpc.php") parameters:params success:^(id responseObject) {
        NSString *code = responseObject[@"return"][@"code"];
        [MBProgressHUD hideHUDForView:self.view];
        if (code.integerValue == 200)
        {
            NSDictionary *dataDict = responseObject[@"return"][@"data"][@"list"][0] ;
            [self showDetailWithDict:dataDict];
        }
        else
        {
            NSString *message = responseObject[@"return"][@"message"];
            [MBProgressHUD showError:message toView:self.view];
        }
    } failure:^(NSError *error) {
        [MBProgressHUD hideHUDForView:self.view];
        [MBProgressHUD showError:@"网络不佳，稍后重试" toView:self.view];
    }];
}

- (void)showDetailWithDict:(NSDictionary *)dict
{
    self.adsTitle.text = dict[@"sitename"];
    self.stopTime.text = [dict[@"stop_sec"] stringByAppendingString:@"秒"];
    self.award.text = [dict[@"real_price"] stringByAppendingString:@"金币"];
    self.adsUrl.text = dict[@"url"];
    self.date.text = [dict[@"create_time"] stringWithDateFormat:@"yyyy-MM-dd hh:mm:ss"];
}


@end
